Answer:

It computes the length of a String

Creating an Object

A program creates an object by following the pattern contained in its class. Here is a program that creates a String object:

class StringDemo1
{
  public static void main ( String[] args )
  {
    String str ;

    str = new String( "Elementary, my dear Watson!" );
  }
}

When the program runs, the phrase

new String( "Elementary, my dear Watson!" )

creates a new String object containing the designated characters. The new object contains all the methods and features that are described in the String class.

The program could now use the methods of this object to do some things with the characters. However, this program does nothing further. After it stops running, the object no longer exists. The memory out of which it was made can now be used for other purposes.

QUESTION 4:

Mentally change the program so that it creates a String object containing the characters "You know my methods, Watson."